/*
<Copyright (C) 2011 Dru Moore>

This file is part of demorecorder.

vlc-remote is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

demorecorder is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with demorecorder.  If not, see <http://www.gnu.org/licenses/>.
*/
import QtQuick 1.1
import com.meego 1.0

Item {
    id: digitalTimer

    height: fontSize + 8
    width: parent.width

    property int milliseconds: 0
    property alias fontSize: counter.font.pixelSize
    property alias fontSpacing: counter.font.letterSpacing
    property alias fontColor: counter.color
    property alias label: label.text

    function _formatTime(ms) {
        return _padLeft('' + Math.floor(ms / 60000), 3, '0')
                + ':'
                + _padLeft('' + Math.floor((ms / 1000) % 60), 2, '0')
                + '.'
                + _padLeft('' + Math.floor((ms / 100) % 10), 1, '0');
    }

    function _padLeft(str, len, padChar) {
        if (!len) len = 2;
        if (!padChar) padChar = '0';
        if (str && str.length < len) return padChar + str;
        else return str;
    }

    Row {

        anchors.fill: parent

        Text {
            id: label
            font.pixelSize: 24
            font.family: "monospace"
            height: parent.height
            text:  ""
            horizontalAlignment: Text.AlignRight
            verticalAlignment: Text.Center
            color: counter.color

        }

        Text {
            id: counter
            width: parent.width - label.width
            font.pixelSize: 12
            font.family: "monospace"
            height: parent.height
            font.letterSpacing: -1
            text: _formatTime(milliseconds)
            horizontalAlignment: Text.AlignRight
            verticalAlignment: Text.Center
            color: "#ffffff"
        }

    }
}
